package com.yawn.zdweb.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * @author Created by yawn on 2018-01-26 13:04
 */
public class EncryptUtil {

    public static String md5Encrypt(String str) {
///        完整加密、编码步骤
//        MessageDigest md5 = MessageDigest.getInstance("MD5");
//        // MD5 编码
//        byte[] result = md5.digest(str.getBytes("utf-8"));
//        // BASE64 编码
//        String base64Code = Base64.getEncoder().encodeToString(result);
//
//        return base64Code;

        try {
            return Base64.getEncoder().encodeToString(MessageDigest.getInstance("MD5").digest(str.getBytes("utf-8")));
        } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
